package com.ysu.yybk.handler;

import com.sun.org.apache.regexp.internal.RE;
import com.ysu.yybk.VO.ResultVO;
import com.ysu.yybk.exception.YybkException;
import com.ysu.yybk.util.ResultVOUtil;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

@ControllerAdvice
public class YybkExceptionHandler {

    @ExceptionHandler(YybkException.class)
    @ResponseBody
    public ResultVO handlerYybkException(YybkException e) {
        return ResultVOUtil.error(e.getCode(), e.getMessage());
    }

    @ExceptionHandler(Exception.class)
    @ResponseBody
    public ResultVO handlerUnknownException(Exception e) {
        return ResultVOUtil.error(-1, e.getMessage());
//        return ResultVOUtil.error(-1, "未知错误");
    }
}
